var db = require( '../db/db' );
var util = require( 'util' );

const tableName = 'core.order_resetpwd';

exports.getTodoOrder = async function ( email, key ) {
    var sql = `SELECT * FROM ${ tableName } WHERE email=$1 AND key=$2 AND success_at IS NULL AND expire_at>now() LIMIT 1`;
    var params = [ email, key ];

    try {

        var result = await db.runSql( sql, params );

        if ( result ) {
            return result.rows;
        }
        return null;

    } catch ( e ) {
        console.error( e );
        return null;
    }
};